<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import routeType from '@/api/routes/routeType'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()



const switchStatus = (statusValue, id, statusName) => {
  routeType.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'route_type',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: routeType.getList,
  recycleApi: routeType.getRecycleList,
  add: {
    show: true,
    api: routeType.save,
    auth: ['routes:routeType:save']
  },
  edit: {
    show: true,
    api: routeType.update,
    auth: ['routes:routeType:update']
  },
  delete: {
    show: true,
    api: routeType.deletes,
    auth: ['routes:routeType:delete'],
    realApi: routeType.realDeletes,
    realAuth: ['routes:routeType:realDeletes']
  },
  recovery: {
    show: true,
    api: routeType.recoverys,
    auth: ['routes:routeType:recovery']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入名称"
    }
  },
  {
    title: "代码",
    dataIndex: "code",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入代码"
    }
  },
  {
    title: "是否关闭",
    dataIndex: "close",
    formType: "switch",
    checkedValue: 1,
    uncheckedValue: 0
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'routes:routeType' } </script>